import { createRouter,  createWebHashHistory } from 'vue-router'
import {generateRoutes} from './addRouter'
import {useMenu} from '../stores/Menu'
const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path:'/',
      redirect:'/dashboard'
    },
    {
      path: '/',
      name: 'home',
      component: () => import('../views/Home.vue'),
      children:[
         {
          path:'/dashboard',
          name:'dashboard',
          meta:{
            title:'系统首页',
            
          },
          component:()=>import('../views/system/paramInfo.vue')  
        },
        {
          path:'/system/paramInfo',
          name:'paramInfo',
          meta:{
            title:'参数信息',
          },
          component:()=>import('../views/system/paramInfo.vue')  
        },
        {
          path:'/system/config',
          name:'config',
          meta:{
            title:'配置信息',
          
          },
          component:()=>import('../views/system/config.vue')  
        },
        {
          path:'/system/backup',
          name:'backup',
          meta:{
            title:'数据库备份',
          
          },
          component:()=>import('../views/system/backup.vue')  
        },
        {
          path:'/user/adminList',
          name:'adminList',
          meta:{
            title:'管理员管理',
           
          },
          component:()=>import('../views/user/AdminList.vue')  
        },
        {
            path:'/user/stuList',
            name:'stuList',
            meta:{
              title:'用户管理',
             
            },
            component:()=>import('../views/user/StudentList1.vue')
        },
        {
          path:'/user/teacherList',
          name:'teacherList',
          meta:{
            title:'教师管理',
           
          },
          component:()=>import('../views/user/TeacherList.vue')
          },
          {
            path:'/user/advisorList',
            name:'advisorList',
            meta:{
              title:'咨询师管理',
             
            },
            component:()=>import('../views/user/AdvisorList.vue')
        },

        {
          path:'/privilege/userGroup',
          name:'userGroup',
          meta:{
            title:'用户组管理',
            
          },
          component:()=>import('../views/privilege/UserGroup.vue')  
        },
        {
          path:'/privilege/roleList',
          name:'roleList',
          meta:{
            title:'角色管理',
           
          },
          component:()=>import('../views/privilege/RoleList.vue')  
        },
        {
          path:'/privilege/rolePriv',
          name:'rolePriv',
          meta:{
            title:'角色权限',
           
          },
          component:()=>import('../views/privilege/RolePriv.vue')  
        },
        {
          path:'/privilege/menuList',
          name:'menuList',
          meta:{
            title:'菜单管理',
            
          },
          component:()=>import('../views/privilege/MenuList.vue')  
        },
        {
          path:'/privilege/menuAction',
          name:'menuAction',
          meta:{
            title:'菜单行为',
            
          },
          component:()=>import('../views/privilege/MenuAction.vue')  
        },
        {
          path:'/privilege/actionList',
          name:'actionList',
          meta:{
            title:'行为管理',
          
          },
          component:()=>import('../views/privilege/actionList.vue')  
        },
        {
          path:'/clazz/major',
          name:'major',
          meta:{
            title:'专业方向',
            
          },
          component:()=>import('../views/clazz/Major.vue')  
        },
        {
          path:'/clazz/clazzList',
          name:'clazzList',
          meta:{
            title:'班级列表',
            
          },
          component:()=>import('../views/clazz/ClazzList.vue')  
        },
        {
          path:'/clazz/question',
          name:'question',
          meta:{
            title:'班级问题',
            
          },
          component:()=>import('../views/clazz/Question.vue')  
        },
        {
          path:'/clazz/homework',
          name:'homework',
          meta:{
            title:'班级问题',
           
          },
          component:()=>import('../views/clazz/Homework.vue')  
        },
        {
          path:'/clazz/studyProcess',
          name:'studyProcess',
          meta:{
            title:'班级问题',
            
          },
          component:()=>import('../views/clazz/StudyProcess.vue')  
        },
        
        {
          path:'/notice/noticeList',
          name:'noticeList',
          meta:{
            title:'公告管理',
            
          },
          component:()=>import('../views/notice/NoticeList.vue')  
        },
        {
          path:'/notice/newsList',
          name:'newsList',
          meta:{
            title:'新闻咨询',
            
          },
          component:()=>import('../views/notice/NewsList.vue')  
        },
        
        {
          path:'/log/list',
          name:'logList',
          meta:{
            title:'日志列表',
           
          },
          component:()=>import('../views/log/LogList.vue')  
        },
        {
          path:'/organization/branchList',
          name:'branchList',
          meta:{
            title:'分支机构',
           
          },
          component:()=>import('../views/organization/BranchList.vue')  
        },
        {
          path:'/organization/orgList',
          name:'orgList',
          meta:{
            title:'机构列表',
            
          },
          component:()=>import('../views/organization/OrgList.vue')  
        },
 
        {
          path:'/:path(.*)',
          name:'notFound',
          meta:{
            title:'没有权限'
          },
          component: () => import(/* webpackChunkName: "403" */ '../views/NoPrivilege.vue'),
         },
        
      ]
      
    },
    {
      path: '/login',
      name: 'login',
      meta: {
          title: '登录',
      },
      component: () => import(/* webpackChunkName: "login" */ '../views/Login.vue'),
      
  },

  
  {
      path: '/403',
      name: '403',
      meta: {
          title: '没有权限',
      },
      component: () => import(/* webpackChunkName: "403" */ '../views/403.vue'),
  },
  ]
})

// 检查是否存在于免登陆白名单
/* function inWhiteList(toPath) {
    const whiteList = ['/login', '/403']
    const path = whiteList.find((value) => {
        // 使用正则匹配
        const reg = new RegExp('^' + value)
        return reg.test(toPath)
    })
    return !!path
} */

router.beforeEach((to, from, next) => {
  console.group('%c%s', 'color:blue', `${new Date().getTime()}  ${to.path} 的全局前置守卫----------`)
    console.log('所有活跃的路由记录列表', router.getRoutes())
    console.groupEnd()
  document.title = `乐码在线智慧平台 - ${to.meta.title}`;
  const role = localStorage.getItem('ms_username');
  let token  = localStorage.getItem('token')

  console.log("to::",to,"from:",from)
  if (!role && to.path !== '/login') {
      next('/login');
  } else {
        //说明已经登录
      /*   console.log("登录之后。。。")
      let menuList = useMenu().menuList
      console.log(menuList+'=====')`
      generateRoutes(menuList) */
      next();
  }
});

export default router
